Repository navigation
cmd/cgo: don't use Go parameter names in exported C wrapper body - #82123
houtinghang wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Since CL 222619 (Go 1.15), the C wrapper that cgo writes to
_cgo_export.c for an exported function uses the Go parameter names
as the C parameter names. The wrapper body declares a struct whose
fields use the C types of the parameters and results, so a parameter
whose name is the same as a C type name shadows that type and the
wrapper fails to compile:
//export F
func F(writeFunc C.writeFunc) { ... }
_cgo_export.c: error: expected specifier-qualifier-list
before 'writeFunc'
Similarly, a parameter named r conflicts with the local variable
that holds multiple results.
Keep the Go parameter names in the declaration in _cgo_export.h,
which is what CL 222619 was for, but use the generated names p0, p1,
... in the definition, as was done before Go 1.15. C does not
require the parameter names of a declaration and a definition to
match, so the header seen by users is unchanged.
AI disclosure: Claude Opus 5.5 assisted with the analysis, the code
and the test in this change.
Fixes golang#44648
1ae693b to
0302d83
Compare
|
This PR (HEAD: 0302d83) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/848406. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/848406. |
Since CL 222619 (Go 1.15), the C wrapper that cgo writes to
_cgo_export.c for an exported function uses the Go parameter names
as the C parameter names. The wrapper body declares a struct whose
fields use the C types of the parameters and results, so a parameter
whose name is the same as a C type name shadows that type and the
wrapper fails to compile:
Similarly, a parameter named r conflicts with the local variable
that holds multiple results.
Keep the Go parameter names in the declaration in _cgo_export.h,
which is what CL 222619 was for, but use the generated names p0, p1,
... in the definition, as was done before Go 1.15. C does not
require the parameter names of a declaration and a definition to
match, so the header seen by users is unchanged.
AI disclosure: Claude Opus 5.5 assisted with the analysis, the code
and the test in this change.
Fixes #44648